<?php

	// Array storing product stockcodes for top-4 boxes.
	$tops = array();
	$tops['Bluetooth'] 		= array('5051495073371', '5051495102101', '5051495108028', '5051495106581');
	$tops['Electronics']            = array('5051495094147', '5051495101692', '5051495094222', '5051495101197');
	$tops['Ladekabel']		= array('5051495000018', '5051495101821', '5051495089860');
	$tops['Case Cover']		= array('5051495086357', '5051495099708', '5051495073098');
	
	$i = 0;
	$prod = array();
	foreach($tops as $key => $value){
		foreach($value as $topStock){
			$XMLInstanceMoreInfo[$key][$i] = new OutputXML('web3g/xml/individuals/'.$topStock.'.xml');
			$prod[$key][$i] = $XMLInstanceMoreInfo[$key][$i]->AllProductInfo();
			$i++;
		}
		$i=0;
	}

?>


<div id="main">
    <div id="hp_dealscontainer">
	<?php
    	//set image checker backup (currently uses $loc to turn relative into absolute)
	   	$ImageChecker->getImg("/web3g/img/accessories/". $v2['StockCode']. ".jpg", "146", "106", $v2['Name'], "", "") ."</a>\n";	
		
//        $Cats = $XMLInstance->GetTopLevelCategories(6);
        $i=1;
        $c=1;
        $dealbox="";
        $list = "";
        foreach($prod as $key => $value){
			$dealboxids="[";
			$dealbox .= "	<div id=\"hpDealBox_".$i."\" class=\"hpDealBox txtBlue\">\n";
			$dealbox .= "		<div class=\"hpDealBoxBorder\">\n";
//            foreach($XMLInstance->GetTopProducts($key,'3') as $v2){
			foreach($value as $v2){
				if($v2['StockCode'] && $c <= 4){
					if($c>1)
						$hide = " hide";
					else
						$hide = "";
					//main deal
					$dealbox .= "		<div id=\"hpDeal". $c . $i ."\" class=\"hpDeal". $hide ."\">\n";
					$dealbox .= "			<div class=\"hpDealImg\">\n";
					$dealbox .= "				<a href=\"/moreinfo/". $v2['StockCode'] ."/". $CleanCode->Encode($key) ."/\">". $ImageChecker->getImg("/web3g/img/accessories/". $v2['StockCode']. ".jpg", "146", "106", $v2['Name'], "", "") ."</a>\n";
					$dealbox .= "			</div>\n";
					$dealbox .= "			<a class=\"hpDealTitle\"><h3 title=\"". $v2['Name'] ."\">". homepage_deal_preptitle($v2['Name'], 17) ."</h3><h4><span class=\"price\">&euro;".number_format($v2['OurPrice'],2)."</span></h4></a>\n";
					$dealbox .= "		</div>\n";
					
					//right hand links
//					$list .= "				<li><a title=\"". $v2['Name'] ."\" href=\"javascript:dealrotator.click({show:'hpDeal". $c . $i. "',close:box". $i ."})\">". homepage_deal_preptitle($v2['Name'], 17) ."<br /><span class=\"price\">&euro;".number_format($v2['OurPrice'],2)."</span></a></li>\n";

//					$list .= "				<li style=\"position:relative;\"><a title=\"". $v2['Name'] ."\" href=\"/moreinfo/". $v2['StockCode'] ."/". $CleanCode->Encode($key) ."/\">". homepage_deal_preptitle($v2['Name'], 17) ."<br /><span class=\"price\">&euro;".number_format($v2['OurPrice'],2)."</span><img src=\"images/spacer.gif\" class=\"spritebg arrow\" style=\"position:absolute; top:10px; left:144px;\" /></a></li>\n";

					$list .= "				<li style=\"position:relative; cursor:pointer;\" onclick=\"window.location='/moreinfo/". $v2['StockCode'] ."/". $catkey ."/'\" onmouseover=\"dealrotator.click({show:'hpDeal". $c . $i. "',close:box". $i ."})\"><a title=\"". $v2['Name'] ."\" href=\"/moreinfo/". $v2['StockCode'] ."/". $CleanCode->Encode($key) ."/\">". homepage_deal_preptitle($v2['Name'], 17) ."<br /><span class=\"price\">&euro;".number_format($v2['OurPrice'],2)."</span><img src=\"images/spacer.gif\" class=\"spritebg arrow\" style=\"position:absolute; top:10px; left:144px;\" /></a></li>\n";

					$dealboxids .= "'hpDeal". $c . $i ."',";
					$c++;
				}
			}
			$dealboxids .= "]";
			$dealbox .= "		<div class=\"hpDealLinks\">\n";
			$dealbox .= "			<ul>\n";
			$dealbox .= "				<li class=\"hp_deallinks_title\">";
			
			$dealbox .= "<a href=\"/search/". $CleanCode->Encode($key) ."/\" class=\"hpDealLinkHeader\">";
			$dealbox .=					strtoupper($key);
			$dealbox.= "<img src=\"images/spacer.gif\" class=\"spritebg arrow\" /></a></li>\n";
			$dealbox .=	$list . "\n";
			$dealbox .= "			</ul>\n";
			$dealbox .= "		</div>\n";
			$dealbox .= "		<script type=\"text/javascript\"> var box". $i ." = ". $dealboxids ."; </script>\n";
			$dealbox .= "		<img src=\"images/spacer.gif\" onload=\"dealrotator.initialize({rotate:false,dealids:". $dealboxids ."});\" />\n";
			$dealbox .= "		</div>\n";
			$dealbox .= "		<img class=\"hpDealBottomShadow\" src=\"/images/productzone/prod_btmshad.png\" />\n";
			$dealbox .= "	</div>\n";
			
			$i++;
			$c = 1;
			$list = "";
			$dealboxids = "";
		}
    ?>
<?php echo $dealbox; ?>

<div class="hp_dealpromo">
	<a href="<?php echo $loc; ?>search/electronics/computing/laptop-and-notebook/"><img src="<?php echo $loc ?>images/homepage/cb_110310_homepagelaptopad_v1.jpg" alt="" /></a>
</div>


    </div>
</div>
<?php
	function homepage_deal_preptitle($title, $index) { //inserts a placed span into the title header so that the reflowing text to be hidden
		if ($index > strlen($title)) return $title . "<span></span>";	//if the space search index is greater than the text size, then don't check.
	
		$newtitle = $title;
		$newtitle_spaceindex = strpos($newtitle, " ", $index);
		if ($newtitle_spaceindex !== false) {
			//insert the span buy substring splitting
			$newtitle = substr($newtitle, 0, $newtitle_spaceindex) . "<span class=\"titlesep\"></span><span class=\"titlehide\">" . substr($newtitle, ($newtitle_spaceindex), (strlen($newtitle) - $newtitle_spaceindex)) . "</span>";
		}
		else { $newtitle .= "<span></span>"; }
		
		return $newtitle;
	}
?>